<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>parseHTML</title>
</head>
<body>
	parseHTML: function( data, context, keepScripts ) {
		if ( !data || typeof data !== "string" ) {
			return null;
		}
		if ( typeof context === "boolean" ) {
			keepScripts = context;
			context = false;
		}
		context = context || document;

		var parsed = rsingleTag.exec( data ),
			scripts = !keepScripts && [];

		// Single tag
		if ( parsed ) {
			return [ context.createElement( parsed[1] ) ];//单标签的创建
		}

		parsed = jQuery.buildFragment( [ data ], context, scripts );//多标签节点，通过文档碎片的形式创建节点

		if ( scripts ) {
			jQuery( scripts ).remove();
		}

		return jQuery.merge( [], parsed.childNodes );
	}


	buildFragment: function( elems, context, scripts, selection ) {
		var elem, tmp, tag, wrap, contains, j,
			i = 0,
			l = elems.length,
			fragment = context.createDocumentFragment(),
			nodes = [];

		for ( ; i < l; i++ ) {
			elem = elems[ i ];

			if ( elem || elem === 0 ) {

				// Add nodes directly
				if ( jQuery.type( elem ) === "object" ) {
					// Support: QtWebKit
					// jQuery.merge because core_push.apply(_, arraylike) throws
					jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem );

				// Convert non-html into a text node
				} else if ( !rhtml.test( elem ) ) {
					nodes.push( context.createTextNode( elem ) );

				// Convert html into DOM nodes
				} else {
					tmp = tmp || fragment.appendChild( context.createElement("div") );

					// Deserialize a standard representation
					tag = ( rtagName.exec( elem ) || ["", ""] )[ 1 ].toLowerCase();
					wrap = wrapMap[ tag ] || wrapMap._default;
					tmp.innerHTML = wrap[ 1 ] + elem.replace( rxhtmlTag, "<$1></$2>" ) + wrap[ 2 ];

					// Descend through wrappers to the right content
					j = wrap[ 0 ];
					while ( j-- ) {
						tmp = tmp.lastChild;
					}

					// Support: QtWebKit
					// jQuery.merge because core_push.apply(_, arraylike) throws
					jQuery.merge( nodes, tmp.childNodes );

					// Remember the top-level container
					tmp = fragment.firstChild;

					// Fixes #12346
					// Support: Webkit, IE
					tmp.textContent = "";
				}
			}
		}
</body>
</html>
<script src='jquery源码分析.js'></script>
<script>
$("<li>fsff</li><p>fwefwe</p>");
	// var str = "<li></li><li></li><script><\/script>";
	var str = "<li>1</li>";
	console.log($.parseHTML(str,document,true));//document是上下文，参数写上false的话，script不会被存到数组里面
</script>
<script>
	var rsingleTag = /^<(\w+)\s*\/?>(?:<\/\1>|)$/;
	var li1=rsingleTag.exec('<li>1</li>');//匹配不到
	console.log(li1);
</script>
<script>
	var rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,
	box1 = rxhtmlTag.exec("<hr/>");
	 // box1="<li>14321</li><p>41221</p>".replace(rxhtmlTag, "<$1></$2>");
	console.log(box1);
	// var rhtml = /<|&#?\w+;/;
	// alert(rhtml.test( "<li>1</li><p>2</p>" ));


	var j=0;
	while(j--){
		alert(1);
	}
</script>
